﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class EmailLog
    {
        private readonly Chain.IDAL.EmailLog dal = new Chain.IDAL.EmailLog();

        public int Add(Chain.Model.EmailLog model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.EmailLog> DataTableToList(DataTable dt)
        {
            List<Chain.Model.EmailLog> list = new List<Chain.Model.EmailLog>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.EmailLog item = new Chain.Model.EmailLog();
                    if ((dt.Rows[i]["EmailID"] != null) && (dt.Rows[i]["EmailID"].ToString() != ""))
                    {
                        item.EmailID = int.Parse(dt.Rows[i]["EmailID"].ToString());
                    }
                    if ((dt.Rows[i]["EmailAdress"] != null) && (dt.Rows[i]["EmailAdress"].ToString() != ""))
                    {
                        item.EmailAdress = dt.Rows[i]["EmailAdress"].ToString();
                    }
                    if ((dt.Rows[i]["EmailTitle"] != null) && (dt.Rows[i]["EmailTitle"].ToString() != ""))
                    {
                        item.EmailTitle = dt.Rows[i]["EmailTitle"].ToString();
                    }
                    if ((dt.Rows[i]["EmailContent"] != null) && (dt.Rows[i]["EmailContent"].ToString() != ""))
                    {
                        item.EmailContent = dt.Rows[i]["EmailContent"].ToString();
                    }
                    if ((dt.Rows[i]["EmailState"] != null) && (dt.Rows[i]["EmailState"].ToString() != ""))
                    {
                        item.EmailState = int.Parse(dt.Rows[i]["EmailState"].ToString());
                    }
                    if ((dt.Rows[i]["EmailSendTime"] != null) && (dt.Rows[i]["EmailSendTime"].ToString() != ""))
                    {
                        item.EmailSendTime = DateTime.Parse(dt.Rows[i]["EmailSendTime"].ToString());
                    }
                    if ((dt.Rows[i]["EmailShopID"] != null) && (dt.Rows[i]["EmailShopID"].ToString() != ""))
                    {
                        item.EmailShopID = int.Parse(dt.Rows[i]["EmailShopID"].ToString());
                    }
                    if ((dt.Rows[i]["EmailUserID"] != null) && (dt.Rows[i]["EmailUserID"].ToString() != ""))
                    {
                        item.EmailUserID = int.Parse(dt.Rows[i]["EmailUserID"].ToString());
                    }
                    if ((dt.Rows[i]["EmailCount"] != null) && (dt.Rows[i]["EmailCount"].ToString() != ""))
                    {
                        item.EmailCount = int.Parse(dt.Rows[i]["EmailCount"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int EmailID)
        {
            return this.dal.Delete(EmailID);
        }

        public bool DeleteList(string EmailIDlist)
        {
            return this.dal.DeleteList(EmailIDlist);
        }

        public int EmailResend(int intEamilID)
        {
            return this.dal.EmailResend(intEamilID);
        }

        public bool Exists(int EmailID)
        {
            return this.dal.Exists(EmailID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.EmailLog GetModel(int EmailID)
        {
            return this.dal.GetModel(EmailID);
        }

        public List<Chain.Model.EmailLog> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.EmailLog model)
        {
            return this.dal.Update(model);
        }

        public int UpdateEmail(int intID, int state)
        {
            return this.dal.UpdateEmail(intID, state);
        }

        public int UpdateEmailCount(int intID)
        {
            return this.dal.UpdateEmailCount(intID);
        }
    }
}

